package com.nfit.shopadmin.controller;

import com.github.pagehelper.PageInfo;
import com.nfit.shopadmin.service.ProductService;
import com.nfit.shopmodel.entity.product.Product;
import com.nfit.shopmodel.entity.product.ProductSku;
import com.nfit.shopmodel.vo.common.Result;
import com.nfit.shopmodel.vo.common.ResultCodeEnum;
import com.nfit.shopmodel.vo.product.ProductDetailsVo;
import com.nfit.shopmodel.vo.product.ProductVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * ClassName:ProductController
 * Package:com.nfit.shopadmin.controller
 * Description
 *
 * @Author L
 * @Create 2024/12/11 10:00
 */
@RestController
@RequestMapping("/admin/product")
public class ProductController {

    @Autowired
    private ProductService productService;

    /**
     * 首页轮播图图片
     */
    @GetMapping("/getProductImage")
    public Result getProductImage() {
       List<Product> list= productService.getProductImage();
       return Result.build(list, ResultCodeEnum.SUCCESS);
    }

    /**
     * 首页热门商品
     */
    @GetMapping("/getHotProduct/{pageNum}/{pageSize}")
    public Result getHotProduct(@PathVariable("pageNum") Integer pageNum,
                                @PathVariable("pageSize") Integer pageSize){
       PageInfo<ProductVo> list = productService.getHotProduct(pageNum,pageSize);
       return Result.build(list,ResultCodeEnum.SUCCESS);
    }

    /**
     * 根据商品id查询商品详情信息
     * @param productId 商品id
     */
    @GetMapping("/getByProductId/{productId}")
    public Result getByProductId(@PathVariable("productId") Long productId){
        ProductDetailsVo productDetailsVo = productService.getByProductId(productId);
        return Result.build(productDetailsVo,ResultCodeEnum.SUCCESS);
    }

}
